package com.may.nio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @program: com.may.netty
 * @description: 使用 transferFrom 拷贝文件
 * @author: Bobby.Ma
 * @create: 2020-08-02 15:15
 **/
public class NIOFileChannel04 {
    /**
     * logger
     */
    private static final Logger log = LoggerFactory.getLogger(NIOFileChannel04.class);

    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\19167\\Documents\\The.Last.Emperor.1987.jpg");
        FileChannel inChannel = fileInputStream.getChannel();

        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\19167\\Documents\\末代皇帝.jpg");
        FileChannel outChannel = fileOutputStream.getChannel();

        //使用 transferFrom 完成拷贝
        outChannel.transferFrom(inChannel, 0, inChannel.size());
        fileInputStream.close();
        fileOutputStream.close();
    }
}
